package com.aididi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：xuzexiang
 * @description：
 * @date ： 2022/3/9 10:53
 */
@RequestMapping("/batch")
@Controller
public class BatchMchntAdjustController {


    @RequestMapping("/index")
    public String index(Model model){
        List<String> list = new ArrayList<>();
        model.addAttribute("list",list);
        model.addAttribute("nums","Y");
        return "table";
    }

    @RequestMapping("/menuMod")
    public String menuMod(Model model,String[] ids){
        JSONObject result  = new JSONObject();
        List<String> list = Arrays.asList(ids);
        List<Map<String,Object>> list_map = new ArrayList<>();
        for ( int i = 0; i < 4; i++) {
            Map<String,Object> map = new HashMap<>();
            map.put("mappId","1111"+i);
            map.put("orgId","1111"+i);
            map.put("mchntNo","UMS229019"+i);
            map.put("settleAmt","20"+i);
            map.put("Amt","1"+i);
            map.put("remark","啊哈哈"+i);
            list_map.add(map);
        }

        result.put("diffList1",list_map);
        model.addAttribute("diffLists",result);
        model.addAttribute("diffList",list_map);
        return "BatchWindow";
    }


    @RequestMapping("/add")
    public JSONObject index(HttpServletRequest request){
        JSONObject result  = new JSONObject();
        String a = request.getParameter("list");
        String [] array = a.split(",");
        List list = new ArrayList();
        for (String s : array) {
            list.add(s.trim());
        }
        result.put("result",true);
        result.put("diffList",list);
        return result;
    }



    @RequestMapping("/list")
    @ResponseBody
    public JSONObject query(){
        JSONObject result  = new JSONObject();
        List<Map<String,Object>> list_map = new ArrayList<>();
        for ( int i = 0; i < 4; i++) {
            Map<String,Object> map = new HashMap<>();
            map.put("mappId","1111"+i);
            map.put("orgId","1111"+i);
            map.put("mchntNo","UMS229019"+i);
            map.put("settleAmt","20"+i);
            map.put("Amt","1"+i);
            map.put("remark","啊哈哈"+i);
            list_map.add(map);
        }
        result.put("result",true);
        result.put("diffList",list_map);
        return result;
    }




    @RequestMapping("/update")
    @ResponseBody
    public JSONObject update(@RequestParam String params){
        JSONObject result  = new JSONObject();
        try {
            JSONArray jsonArray = JSONArray.parseArray(params);
            for (int i = 0; i < jsonArray.size(); i++) {
                JSONObject jsonObject  = jsonArray.getJSONObject(i);
                String mappId = jsonObject.getString("mappId");
                String Amt = jsonObject.getString("Amt");
                String settleAmtAdjust = jsonObject.getString("settleAmtAdjust");
            }
            result.put("msg","成功");
            result.put("result",true);
        }catch (Exception e){
            result.put("msg",e.getMessage());
            result.put("result",false);
        }
        return result;

    }

}
